<?php

class UserController extends AdminController
{
    public $layout = '//layouts/null';
	public function actionIndex()
	{

		$this->render('index');
	}
    //获取会员数据
    public function actiongetList() {
        if(Yii::app()->request->isAjaxRequest){
            $page = Yii::app()->request->getParam('page');
            $rows = Yii::app()->request->getParam('rows');
            $order = Yii::app()->request->getParam('order');
            $sort = Yii::app()->request->getParam('sort');
            $username = Yii::app()->request->getParam('username');
            $date_from = strtotime(Yii::app()->request->getParam('date_from'));
            $date_to = strtotime(Yii::app()->request->getParam('date_to'));
            $info = User::model()->getList($page,$rows,$order,$sort,$username,$date_from, $date_to);
            echo json_encode($info);
            Yii::app()->end();
        } else {
            exit('非法操作');
        }
    }
    public function actionRemove(){
        if (Yii::app()->request->isAjaxRequest) {
            $ids = Yii::app()->request->getParam('ids');
            echo User::model()->remove($ids);
        } else {
            exit('非法操作');
        }
    }
    public function actionRegister(){
        if (Yii::app()->request->isAjaxRequest) {
            $username = Yii::app()->request->getParam('username');
            $password = Yii::app()->request->getParam('password');
            $nickname = Yii::app()->request->getParam('nick_name');
            $email = Yii::app()->request->getParam('email');
            $sex = Yii::app()->request->getParam('sex');
            $phone = Yii::app()->request->getParam('phone');
            echo $ok = User::model()->create($username,$password,$nickname,$email,$sex,$phone);
        } else {
            exit('非法操作');
        }
    }
    public function actionGetUser(){
        $id = intval(Yii::app()->request->getParam('id'));
        $User = User::model();
        $info = $User->getUser($id);
        $this->ajaxReturn($info);
        Yii::app()->end();
    }
    public function actionUpdate(){
        if (Yii::app()->request->isAjaxRequest) {
            $id = intval(Yii::app()->request->getParam('id'));
            $username = Yii::app()->request->getParam('username');
            $password = Yii::app()->request->getParam('password');
            $nickname = Yii::app()->request->getParam('nick_name');
            $email = Yii::app()->request->getParam('email');
            $sex = Yii::app()->request->getParam('sex');
            $phone = Yii::app()->request->getParam('phone');
            echo $ok = User::model()->edit($id,$username,$password,$nickname,$email,$sex,$phone);
        } else {
            exit('非法操作');
        }
    }
    public function actionShow(){
        if (Yii::app()->request->isAjaxRequest) {
            $id = intval(Yii::app()->request->getParam('id'));
            $info = User::model()->findByPk($id);
            $this->renderPartial('show',array('info'=>$info));
        } else {
            exit('非法操作');
        }

    }
    public function actionSetStatus(){
        if (Yii::app()->request->isAjaxRequest) {
            $id = intval(Yii::app()->request->getParam('id'));
            $type = intval(Yii::app()->request->getParam('type'));
            $info = User::model()->findByPk($id);
            $info->status = $type;
            $ok = $info->update();
            if($ok){
                $data['status'] = 1;
            }else{
                $data['status'] = 0;
            }
            echo json_encode($data);
        } else {
            exit('非法操作');
        }
    }
}